﻿package server;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ComBuyList extends UnicastRemoteObject implements ComBuyInterface{
	
	private Data data;
	protected ComBuyList() throws RemoteException {
		super();
		data =new Data();
	}

	public String kind;
	public int Hap;
	public double money;
	
	
	public int getHap(String kind) throws RemoteException{
		String sql;
		ResultSet rs=null;
		int Hap=0;
		
		sql="select * from combuylist where housekind='" + kind+"'";
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				Hap=rs.getInt("hap");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
		return Hap;
	}
	
	public double getMon(String kind) throws RemoteException{
		String sql;
		ResultSet rs=null;
		double money=0;
		
		sql="select * from combuylist where housekind='" + kind+"'";
		rs=data.getResultSet(sql);
		try {
			while(rs.next()){
				money=rs.getDouble("money");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
		return money;
	
	}
	
	public int getSize() throws RemoteException{
		String sql;
		ResultSet rs=null;
		int sum=0;
		
		sql="select count(*) as sum from combuylist";
		rs=data.getResultSet(sql);
		try {
			if(rs.next()){
				sum=rs.getInt("sum");
		}
			} catch (SQLException e) {
		
			e.printStackTrace();
			}
		return sum;
	}
	

}
